﻿using MDIApplication.Classes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MDIApplication
{
    public partial class UpdateStaffSuccessful : Form
    {
        public UpdateStaffSuccessful(string firstName, string lastName, string staffId)
        {
            InitializeComponent();
            lblfirstNameshow.Text = firstName;
            lbllastNameshow.Text = lastName;
            lblaccountID.Text = staffId;

           
        }
        #region toolStrip
        UpdateRoomInfo updateRoomInfoChild;
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            CloseAllForms();
            if (updateRoomInfoChild == null)
            {
                updateRoomInfoChild = new UpdateRoomInfo();
                updateRoomInfoChild.MdiParent = this.MdiParent;
                updateRoomInfoChild.Location = new Point(0, 0);
                // Display the form.
                updateRoomInfoChild.Show();
                updateRoomInfoChild.Activate();
            }

        }

        SearchForStaffHousekeepDuty dutyAllocationChild;
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            CloseAllForms();
            if (dutyAllocationChild == null)
            {
                dutyAllocationChild = new SearchForStaffHousekeepDuty();
                dutyAllocationChild.MdiParent = this.MdiParent;
                dutyAllocationChild.Location = new Point(0, 0); ;
                // Display the form.
                dutyAllocationChild.Show();
                dutyAllocationChild.Activate();
            }
        }

        SearchForStaff updateStaffChild;
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            CloseAllForms();
            if (updateStaffChild == null)
            {
                updateStaffChild = new SearchForStaff();
                updateStaffChild.MdiParent = this.MdiParent;
                updateStaffChild.Location = new Point(0, 0);
                // Display the form.
                updateStaffChild.Show();
                updateStaffChild.Activate();
            }
        }
        #endregion toolStrip

        private void UpdateStaffSuccessful_Load(object sender, EventArgs e)
        {
            HousekeepingStaffManagementDBManager db = new HousekeepingStaffManagementDBManager();
            Staff s = db.getStaffByStaffName(lblfirstNameshow.Text, lbllastNameshow.Text);

            lblfirstName.Text = s.firstName;
            lbllastName.Text = s.lastName;
            lblcontactNum.Text = s.contactNo.ToString();
            lbldob.Text = s.dob.ToLongDateString();
            lblgender.Text = s.gender;
            lbladdress.Text = s.address;
            lblstaffPosition.Text = s.staffPosition;
            lblbankAcctType.Text = s.acctType.ToString();
            lblbankAcctNum.Text = s.acctNo;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            CloseAllForms();
            if (updateStaffChild == null)
            {
                updateStaffChild = new SearchForStaff();
                updateStaffChild.MdiParent = this.MdiParent;
                updateStaffChild.Location = new Point(0, 0);
                // Display the form.
                updateStaffChild.Show();
                updateStaffChild.Activate();
            }
        }

       
        #region CloseAllForms
        private void CloseAllForms()
        {
            Form[] formToClose = null;
            int i = 1;
            foreach (Form form in Application.OpenForms)
            {
                if (form != this && form.IsMdiChild) //this is form1
                {
                    Array.Resize(ref formToClose, i);
                    formToClose[i - 1] = form;
                    i++;
                }
            }
            if (formToClose != null)
            {
                for (int j = 0; j < formToClose.Length; j++)
                {
                    formToClose[j].Close();
                }
                updateRoomInfoChild = null;
                dutyAllocationChild = null;
                updateStaffChild = null;
            }
        }
        #endregion CloseAllForms
        
    }
}
